#pragma once
#include <iostream>
#include <string>
#include "InetAddr.hpp"

using namespace std;
using namespace LogModule;

using handler_t=function<string(string&)>;

class Reactor;
class Connection;

//封装fd，保证每个fd一套缓冲区
//基类 
class Connection
{
public:
    Connection()
    {

    }
    virtual void Recver()=0;
    virtual void Sender()=0;
    virtual void EXcepter()=0;  //异常处理
    virtual int GetSockFd() = 0;
    
    void SetEvent(const uint32_t &events)//获取事件
    {
        _events=events;
    }
    uint32_t GetEvent()//返回事件
    {
        return _events; 
    }

    void SetOwner(Reactor* owner)//设置回指指针
    {
        _owner=owner;
    }
    Reactor* GetOwner()//返回回指指针
    {
        return _owner;
    }
    void RegisterHandler(handler_t handler)
    {
        _handler=handler;
    }
    ~Connection()
    {

    }
private:  
    Reactor *_owner; //回指指针
    uint32_t _events; //关系的事件
public:
    handler_t _handler;
};
